import { Button } from 'antd'
import { ConfigProvider } from 'antd/lib'

type ThemedButtonType =
  | 'primary'
  | 'success'
  | 'warning'
  | 'error'
  | 'link'
  | 'text'
  | 'dashed'
  | 'default'
  | undefined

const ThemedButton = ({
  type = 'default',
  ...props
}: {
  type: ThemedButtonType
}) => {
  const buttonThemes = {
    success: {
      token: {
        colorPrimary: '#52c41a',
      },
    },
    warning: {
      token: {
        colorPrimary: '#faad14',
      },
    },
    error: {
      token: {
        colorPrimary: '#ff4d4f',
      },
    },
    primary: undefined,
    default: undefined,
    dashed: undefined,
    link: undefined,
    text: undefined,
  }

  // 如果是自定义类型，使用ConfigProvider包裹
  if (
    buttonThemes[type] &&
    type !== 'primary' &&
    type !== 'default' &&
    type !== 'dashed' &&
    type !== 'link' &&
    type !== 'text'
  ) {
    return (
      <ConfigProvider theme={buttonThemes[type]}>
        <Button type="primary" {...props} />
      </ConfigProvider>
    )
  }

  return (
    <Button
      type={
        type as 'default' | 'link' | 'text' | 'primary' | 'dashed' | undefined
      }
      {...props}
    />
  )
}

export default ThemedButton
